package com.baturu.vin.hyundai.dal.dao;

import com.baturu.vin.hyundai.dal.entity.HyundaiKiaFeatureEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

public interface HyundaiKiaFeatureDAO {

    @Select({"<script>" +
            "select code,message,model " +
            "from hyundai_feature " +
            "WHERE code IN " +
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" ,
            "AND lang = #{lang} ",
            "</script>"})
    List<HyundaiKiaFeatureEntity> queryByCode(@Param("codes") Collection<String> codes, @Param("lang") String lang);

    @Insert({"<script>" +
            "INSERT IGNORE INTO hyundai_feature(model,code,message,type,lang) VALUES " +
            "<foreach item='item' index='index' collection='features' open='' separator=',' close=''>" +
            "(#{item.model},#{item.code},#{item.message},#{item.type},#{lang})" +
            "</foreach>" ,
//            "on duplicate key update message = values(message)",
            "</script>"})
    void save(@Param("features") Collection<HyundaiKiaFeatureEntity> features,@Param("lang") String lang);

    @Select("<script>" +
            "select `code`,message,feature from hyundai_feature " +
            "WHERE feature !='' and code IN " +
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<HyundaiKiaFeatureEntity> queryFeatures(@Param("codes") Collection<String> codes);

    @Select("<script>" +
            "select `code`,message,material from hyundai_feature " +
            "WHERE material !='' and code IN " +
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<HyundaiKiaFeatureEntity> queryMaterial(@Param("codes") Collection<String> codes);
}